{include file="public/layout" /}
<body class="eyou_body_xin">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
{include file="system/left" /}
<div id="geduan_div" class="h15"></div>
<style type="text/css">
    .tb_child { background: #FFFFDF; }
</style>
<div class="page arctype" style="min-width:auto;margin-left:115px;padding-bottom: 15px;">
    <!-- 操作说明 -->
    <!--<div id="explanation" class="explanation" style="color: rgb(44, 188, 163); background-color: rgb(237, 251, 248); width: 99%; height: 100%;margin-bottom: 15px;">-->
        <!--<div id="checkZoom" class="title"><i class="fa fa-lightbulb-o"></i>-->
            <!--<h4 title="提示相关设置操作时应注意的要点">提示</h4>-->
            <!--<span title="收起提示" id="explanationZoom" style="display: block;"></span>-->
        <!--</div>-->
        <!--<ul>-->
            <!--<li>商品添加只允许发布在最后一级分类</li>-->
            <!--<li>在小程序端展示不同的分类页面的模板风格</li>-->
        <!--</ul>-->
    <!--</div>-->
    
    <div class="flexigrid">
        <div class="mDiv pt0">
            <div class="ftitle">
                {eq name="'Help@arctype_add'|is_check_access" value="1"}
                <div class="fbutton"><a href="{:url('Help/arctype_add')}"><div class="add"><span><i class="layui-icon layui-icon-addition"></i>新增帮助分类</span></div></a></div>
                {/eq}
            </div>
        </div>

        <div class="hDiv">
            <div class="hDivBox">
                <table cellpadding="0" cellspacing="0" style="width: 100%">
                    <thead>
                        <tr>
                            <th axis="col3" class="">
                                <div class="sundefined text-l10">
                                    <!--{if condition="!empty($tree['cookied_treeclicked']) && $tree.cookied_treeclicked_str != $type_id"}-->
                                    <!--<img src="__SKIN__/images/tv-collapsable-last.gif" id="all_treeclicked" title="关闭所有子分类" style="float: none;" data-status="open" onclick="treeClicked(this, 'all', 0);">-->
                                    <!--{else /}-->
                                    <!--<img src="__SKIN__/images/tv-expandable.gif" id="all_treeclicked" title="展开所有子分类" style="float: none;" data-status="close" onclick="treeClicked(this, 'all', 0);">-->
                                    <!--{/if}-->
                                    分类名称
                                </div>
                            </th>
                            <!--<th axis="col2" class="w100"> <div class="tc">分类图片</div> </th>-->
                            <!-- <th axis="col2" class="w80"> <div class="tc">显示</div> </th> -->
                            <th axis="col1" class="w150"> <div class="tc">创建时间</div> </th>
                            <th axis="col1" class="w100"> <div class="tc">操作</div> </th>
                            <th axis="col2" class="w60"> <div class="tc">排序</div> </th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>

        <div id="flexigrid" class="bDiv" style="height: auto;">
        {empty name="arctype_list"}
            <div id="" cellpadding="0" cellspacing="0" border="0">
                <table>
                    <tbody>
                        <tr>
                            <td class="no-data" align="center" axis="col0" colspan="50">
                                <div class="no_row"> <div class="no_pic"> <img src="__SKIN__/images/null-data.png"> </div> </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="iDiv" style="display: none;"></div>
        {else /}
            <table class="flex-table autoht" cellpadding="0" cellspacing="0" border="0" id="arctype_table" style="width: 100%">
                <tbody id="treet1">
                {foreach name="arctype_list" item="vo" key="k" }
                    <tr nctype="0" {if condition="!in_array($vo.parent_id,$tree.cookied_treeclicked) && 0 < $vo.parent_id "} style="display:none;"{/if} class="parent_id_{$vo['parent_id']}" data-level="{$vo['level']}" data-id="{$vo['id']}">
                        <td class="typename" style="width: 100%">
                            <div>
                                {gt name='vo.level' value='0'}
                                {php}
                                if (2 == $vo['level']) {
                                    echo '<span class="w40x"></span>';
                                } else if ($vo['level'] >= 3) {
                                    echo '<span class="w40x w40xc'.$vo['level'].'" style="margin-right:'.(($vo['level'] - 1) * 25).'px;"></span>';
                                }
                                {/php}
                                {/gt}
                                <!--{gt name="vo.has_children" value="0"}-->
                                <!--<img src="{in name='$vo.id' value='$tree.cookied_treeclicked'}__SKIN__/images/tv-collapsable-last.gif{else /}__SKIN__/images/tv-expandable.gif{/in}" style="float: none;" fieldid="2" status="open" nc_type="flex" onclick="treeClicked(this, {$vo['id']}, 0);" class="has_children childrenImg" data-level="{$vo['level']}" data-id="{$vo['id']}">-->
                                <!--{else /}-->
                                <!--<img src="__SKIN__/images/tv-collapsable-last.gif" style="float: none;" fieldid="2" status="open" nc_type="flex" class="childrenImg">-->
                                <!--{/gt}-->
                                {eq name="'Help@arctype_add'|is_check_access" value="1"}
                                <input type="text" onchange="changeTableVal('arctype', 'id', '{$vo.id}', 'typename', this);" value="{$vo.typename}"/>
                                {else /}
                                {$vo.typename}
                                {/eq}
                            </div>
                        </td>
                        <!--<td class="sort">-->
                            <!--<div class="w100 tc p0">-->
                                <!--<div class="image-li">-->
                                    <!--<img class="image-content" id="litpic_{$vo.id}" src="{$vo.litpic|default='__PUBLIC__/static/common/images/not_upload_pic.png'}" {eq name="'Help@arctype_add'|is_check_access" value="1"} onclick="recordArctypeID({$vo.id});" title="点击更换图片" {/eq}>-->
                                    <!--<span class="s-tihuan">替换</span>-->
                                <!--</div>-->
                            <!--</div>-->
                        <!--</td>-->
                        <!-- <td align="center" class="">
                            <div class="w80 tc">
                                {if condition='$vo.is_hidden eq 1'}
                                <span class="no" {eq name="'Help@arctype_add'|is_check_access" value="1"} onclick="changeTableVal('arctype', 'id', '{$vo.id}', 'is_hidden', this);" {/eq} ><i class="fa fa-ban"></i>否</span>
                                {else /}
                                <span class="yes" {eq name="'Help@arctype_add'|is_check_access" value="1"} onclick="changeTableVal('arctype', 'id', '{$vo.id}', 'is_hidden', this);" {/eq} ><i class="fa fa-check-circle"></i>是</span>
                                {/if}
                            </div>
                        </td> -->
                        <td class="sort"> <div class="w150 tc"> {$vo.add_time|date='Y-m-d H:i:s',###} </div> </td>
                        <td class="operation">
                            <div class="w100 tc">
                                <a href="{:url('Help/arctype_edit', ['id'=>$vo['id']])}" class="btn blue">编辑</a>
                                <!--{eq name="'Help@arctype_add'|is_check_access" value="1"}-->
                                <!--<i></i>-->
                                <!--{if condition="$vo['grade'] < ($arctype_max_level - 1)"}-->
                                <!--<a href="{:url('Help/arctype_add', ['parent_id'=>$vo['id']])}" class="btn blue">增加子分类</a>-->
                                <!--{else /}-->
                                <!--<a class="btn grey" title="不支持增加四级分类">不支持增加</a>-->
                                <!--{/if}-->
                                <!--{/eq}-->
                                {eq name="'Arctype@arctype_del'|is_check_access" value="1"}
                                <i></i>
                                <a class="btn red"  href="javascript:void(0);" data-url="{:url('Arctype/pseudo_del')}" data-id="{$vo.id}" data-typename="{$vo.typename}" data-deltype="del" onClick="delfun(this);">删除</a>
                                {/eq}
                            </div>
                        </td>
                        <td class="sort">
                            <div class="w60 tc">
                                {eq name="'Help@arctype_add'|is_check_access" value="1"}
                                    <input type="text" onchange="changeTableVal('arctype', 'id', '{$vo.id}', 'sort_order', this);" size="4" value="{$vo.sort_order}" class="tc" onkeyup="this.value=this.value.replace(/[^\d]/g,'');" onpaste="this.value=this.value.replace(/[^\d]/g,'')"/>
                                {else /}
                                    {$vo.sort_order}
                                {/eq}
                            </div>
                        </td>
                    </tr>
                {/foreach}
                </tbody>
            </table>
        {/empty}
        </div>
    </div>
</div>

<script type="text/javascript">
    // 删除分类
    function arctypeDel(id) {
        var msgHtml = '确认删除分类？删除时子分类会一起删除，所属商品更新为无分类！';
        layer.alert(msgHtml, {
            move: false,
            closeBtn: 3,
            btnAlign:'r',
            title: '提示',
            shade: layer_shade,
            btn: ['确定', '取消'],
            area: ['480px', '190px'],
            success: function () {
                $(".layui-layer-content").css('text-align', 'left');
            }
        }, function() {
            layer_loading('正在处理');
            $.ajax({
                type: 'post',
                url : "{:url('Arctype/arctype_del')}",
                data: {id: id, _ajax: 1},
                dataType: 'json',
                success: function(res) {
                    layer.closeAll();
                    if (1 === parseInt(res.code)) {
                        layer.msg(res.msg, {icon: 1, time: 1500}, function() {
                            window.location.reload();
                        });
                    } else {
                        // 提示内容
                        showErrorMsg(res.msg);
                    }
                }
            });
        });
    }
</script>
<script type="text/javascript">
    $(function() {
        setCookies('eyou-admin-treeClicked-help-Arr',JSON.stringify({$tree.cookied_treeclicked_arr}) );
    });
    
    // 记录当前点击要上传图片的分类ID
    var arctypeID = 0;
    function recordArctypeID(id) {
        arctypeID = id;
        // 调用图片上传
        GetUploadify(1, '', 'allimg', 'uploadLitPicCallBack');
    }

    // 上传更新分类图片
    function uploadLitPicCallBack(litpic) {
        if (litpic) {
            layer_loading('正在处理');
            // 确定
            $.ajax({
                type: "post",
                url : "{:url('Help/ajaxArctypeLitpicUpload')}",
                data: {id: arctypeID, litpic: litpic, _ajax:1},
                dataType: 'json',
                success: function(res) {
                    layer.closeAll();
                    if (1 === parseInt(res.code)) {
                        $('#litpic_' + arctypeID).attr('src', litpic);
                        layer.msg(res.msg, {icon: 1, time: 1500});
                    } else {
                        layer.alert(res.msg, {icon: 2, title: false});
                    }
                }
            })
        }
    }

     // 点击展开 收缩节点
    function treeClicked(obj,id,reload) {
        if (id == 'all') {
            if (1 == reload) {
                var status = getCookie('admin-treeClicked-help');
                if (!status) status = $(obj).attr('data-status');
            } else {
                var status = $(obj).attr('data-status');
            }
            if (status == 'close') {
                setCookies('eyou-admin-treeClicked-help-Arr', JSON.stringify({$tree.parent_ids}));
                setCookies('eyou-admin-treeClicked-help-All', 1);//1为全部展开,0-为非全部展开
                $('tr[class^=parent_id_]').show();
                $('.childrenImg').attr('src', '__SKIN__/images/tv-collapsable-last.gif');
                $(obj).attr('data-status', 'open').attr('title','关闭所有子分类').attr('src','__SKIN__/images/tv-collapsable-last.gif');
            } else {
                setCookies('eyou-admin-treeClicked-help-Arr', '');
                setCookies('eyou-admin-treeClicked-help-All', 0);
                $('tr[data-level=1]').find('img.has_children').attr('src', '__SKIN__/images/tv-collapsable-last.gif').trigger('click');
                $('tr[class^=parent_id_]').removeClass('trSelected');
                $(obj).attr('data-status', 'close').attr('title','展开所有子分类').attr('src','__SKIN__/images/tv-expandable.gif');
            }
            setCookies('admin-treeClicked-help', status);
            return false;
        }

        var src = $(obj).attr('src');
        if (src == '__SKIN__/images/tv-expandable.gif') {
            var arr = [];
            var str = getCookie('eyou-admin-treeClicked-help-Arr');
            if ('' == str || null == str || 'null' == str) {
                arr.push(id);
            } else {
                arr = JSON.parse(str);
                if (!arr.includes(id))arr.push(id);
            }
            arr = JSON.stringify(arr);
            setCookies('eyou-admin-treeClicked-help-Arr', arr);
            $(".parent_id_"+id).show();
            $(obj).attr('src','__SKIN__/images/tv-collapsable-last.gif');
            var status = 'close';
        } else {
            var key = -1;
            var arr = [];
            var level = '';
            var str = getCookie('eyou-admin-treeClicked-help-Arr');
            if ('' != str) {
                arr = JSON.parse(str);
                key = $.inArray(id,arr);
                if (-1 < key) arr.splice(key,1);
                level = $(obj).attr('data-level');
                $(obj).parent().parent().parent().nextAll().each(function() {
                    if ($(this).attr('data-level') > level) {
                        key = $.inArray(parseInt($(this).attr('data-id')), arr);
                        if (-1 < key) arr.splice(key,1);
                    } else {
                        return false;
                    }
                });
                arr = JSON.stringify(arr);
                setCookies('eyou-admin-treeClicked-help-Arr', arr);
                setCookies('eyou-admin-treeClicked-help-All', 0);
            }

            var status = 'open';
            $(obj).attr('src', '__SKIN__/images/tv-expandable.gif');     

            // 如果是点击减号, 遍历循环他下面的所有都关闭
            var fnd = false;
            var cur_tr = obj.parentNode.parentNode.parentNode;
            var tbl = document.getElementById("arctype_table");
            for (var i = 0; i < tbl.rows.length; i++) {
                var row = tbl.rows[i];
                if (row == cur_tr) {
                    fnd = true;
                } else {
                    if (fnd == true) {
                        var cur_level = $(cur_tr).data('level');
                        var level = parseInt($(row).data('level'));
                        if (level > cur_level) {
                            $(row).hide();        
                            $(row).find('img.has_children').attr('src','__SKIN__/images/tv-expandable.gif');
                        } else {
                            fnd = false;
                            break;
                        }
                    }
                }
            }
        }
        setCookies('admin-treeClicked-help', status);
    }
  
    function delfun(obj){
        var title = $(obj).attr('data-typename');
        var deltype = $(obj).attr('data-deltype');
        var confirm_title = '确认删除到回收站？子分类及文档将一起清空至回收站。';
        if ('del' == deltype) {
            confirm_title = '确认直接删除？子分类及文档将一起清空。';
        }
        layer.confirm(confirm_title, {
            area: ['480px', '190px'],
            move: false,
            title: '提示',
            btnAlign:'r',
            closeBtn: 3,
            shade: layer_shade,
            btn: ['确定','取消'] ,//按钮
            success: function () {
                  $(".layui-layer-content").css('text-align', 'left');
              }
        }, function(){
            layer_loading('正在处理');
            // 确定
            $.ajax({
                type : 'post',
                url : $(obj).attr('data-url'),
                data : {del_id:$(obj).attr('data-id'),deltype:deltype,_ajax:1},
                dataType : 'json',
                success : function(data){
                    layer.closeAll();
                    if(data.code == 1){
                        layer.msg(data.msg, {icon: 1});
                        window.location.reload();
                        // $('tr[data-id="'+$(obj).attr('data-id')+'"]').remove();
                    }else{
                        layer.alert(data.msg, {icon: 2, title:false});  //alert(data);
                    }
                }
            })
        }, function(index){
            layer.close(index);
        });
        return false;
    }

    /* 生成静态页面代码 */
    var typeid = "{$typeid}";
    var is_del = "{$is_del}";
    if (typeid > 0) {
        {eq name='$eyou.seo_pseudo' value='2'}
        $.ajax({
            url: __root_dir__ + "/index.php?m=home&c=Buildhtml&a=upHtml&t_id="+typeid+"&is_del="+is_del+"&ctl_name=Arctype&_ajax=1",
            type: 'GET',
            dataType: 'json',
            data: {},
            success: function (data) {

            }
        });
        {/eq}
        {notempty name='$eyou.zzbaidutoken'}
        // 百度自动推送
        push_zzbaidu('{$eyou.typeurl}', '{$eyou.handle}');
        {/notempty}
        {notempty name='$eyou.bdminipro'}
        //百度小程序 API 提交 (自动推送)
        push_bdminipro(typeid, 1);
        {/notempty}
    }
    /* end */
</script>
{include file="public/footer" /}